package com.mooc.lib_find.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.viewpager.widget.PagerAdapter
import com.mooc.lib_find.model.FindTabEntity

class FindVPAdapter (tab : ArrayList<FindTabEntity>,view : ArrayList<View>): PagerAdapter() {

    var tabs = tab
    var views = view

    override fun getCount(): Int {
        return views.size
    }

    override fun isViewFromObject(view: View, `object`: Any): Boolean {
        return view == `object`
    }

    override fun destroyItem(container: ViewGroup, position: Int, `object`: Any) {
        var view = `object` as View
        container.removeView(view)
    }

    override fun instantiateItem(container: ViewGroup, position: Int): Any {
        val lp = ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.MATCH_PARENT)
        views[position].layoutParams = lp
        container.addView(views[position])
        return views[position]
    }

    override fun getPageTitle(position: Int): CharSequence? {
        return tabs[position].title
    }

}